package com.shop2cn.iapi.member.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.member.parameter.NeedCollectionMobileBean;
import com.shop2cn.iapi.member.service.NeedCollectionMobileCall;
import com.ymatou.iapi.dguser.parameter.UserCreateBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.DGUserCallService;
import com.ymttest.business.service.GodMemberService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.sqlwapper.godmember.GodMemberWapper;
import com.ymttest.utils.TestDataManager;
/**
*是否需要采集手机号
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_NeedCollectionMobile{
	private static NeedCollectionMobileBean needcollectionmobileBean;
	private static NeedCollectionMobileCall needcollectionmobileCall;
	private static Integer shopid ;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("是否需要采集手机号");
	}

	@Before
	public void caseUp() {
		needcollectionmobileBean=new NeedCollectionMobileBean();
		needcollectionmobileCall=new NeedCollectionMobileCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(needcollectionmobileCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_NeedCollectionMobile_001() {
		Logger.start(true,"是否需要采集手机号成功-需要");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			shopid= GodmchManageCallService.CreateSellerMch();
			GodMemberService.setCollectionMobile(shopid, true);
			needcollectionmobileBean.setUserId(userId);
			needcollectionmobileBean.setShopId(shopid);
			needcollectionmobileCall.setData(needcollectionmobileBean);
			needcollectionmobileCall.callService();			
			Logger.verifyEquals("200", needcollectionmobileCall.getString("code"), "验证code");
			Logger.verifyEquals(true, needcollectionmobileCall.getCollectionMobile(), "验证collectionMobile");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_NeedCollectionMobile_002() {
		Logger.start(true,"不输入userid失败");
		try {
//			needcollectionmobileBean.setUserId(1);
			needcollectionmobileBean.setShopId(shopid);
			needcollectionmobileCall.setData(needcollectionmobileBean);
			needcollectionmobileCall.callService();			
			Logger.verifyEquals("400", needcollectionmobileCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_NeedCollectionMobile_003() {
		Logger.start(true,"不输入shopid失败");
		try {
			needcollectionmobileBean.setUserId(1);
//			needcollectionmobileBean.setShopId(shopid);
			needcollectionmobileCall.setData(needcollectionmobileBean);
			needcollectionmobileCall.callService();			
			Logger.verifyEquals("400", needcollectionmobileCall.getString("code"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_NeedCollectionMobile_004() {
		Logger.start(true,"是否需要采集手机号成功-用户已绑定手机不需要");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			shopid= GodmchManageCallService.CreateSellerMch();
			GodMemberService.setCollectionMobile(shopid, true);
			GodMemberService.bindMobile(shopid, userId, TestDataManager.getPhoneNum());
			needcollectionmobileBean.setUserId(userId);
			needcollectionmobileBean.setShopId(shopid);
			needcollectionmobileCall.setData(needcollectionmobileBean);
			needcollectionmobileCall.callService();			
			Logger.verifyEquals("200", needcollectionmobileCall.getString("code"), "验证code");
			Logger.verifyEquals(false, needcollectionmobileCall.getCollectionMobile(), "验证collectionMobile");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_NeedCollectionMobile_005() {
		Logger.start(true,"是否需要采集手机号成功-商家设置不需要");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			shopid= GodmchManageCallService.CreateSellerMch();
//			GodMemberService.setCollectionMobile(shopid, true);
//			GodMemberService.bindMobile(shopid, userId, TestDataManager.getPhoneNum());
			needcollectionmobileBean.setUserId(userId);
			needcollectionmobileBean.setShopId(shopid);
			needcollectionmobileCall.setData(needcollectionmobileBean);
			needcollectionmobileCall.callService();			
			Logger.verifyEquals("200", needcollectionmobileCall.getString("code"), "验证code");
			Logger.verifyEquals(false, needcollectionmobileCall.getCollectionMobile(), "验证collectionMobile");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_NeedCollectionMobile_006() {
		Logger.start(true,"输入不存在userid");
		try {
			//未知id当需要处理
			shopid= GodmchManageCallService.CreateSellerMch();
			GodMemberService.setCollectionMobile(shopid, true);
			needcollectionmobileBean.setUserId(1);
			needcollectionmobileBean.setShopId(shopid);
			needcollectionmobileCall.setData(needcollectionmobileBean);
			needcollectionmobileCall.callService();			
			Logger.verifyEquals("200", needcollectionmobileCall.getString("code"), "验证code");
			Logger.verifyEquals(true, needcollectionmobileCall.getCollectionMobile(), "验证collectionMobile");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_NeedCollectionMobile_007() {
		Logger.start(true,"是否需要采集手机号成功-需要-会员邀请制开关");
		try {
			UserCreateBean usercreateBean = DGUserCallService.initUsercreateBean();
			int userId = DGUserCallService.UserCreateCall(usercreateBean);
			shopid= GodmchManageCallService.CreateSellerMch();
			GodMemberService.setCollectionMobile(shopid, true);
			new GodMemberWapper().updateMchmemberConfigNeedInvitationCode(shopid, true);
			needcollectionmobileBean.setUserId(userId);
			needcollectionmobileBean.setShopId(shopid);
			needcollectionmobileCall.setData(needcollectionmobileBean);
			needcollectionmobileCall.callService();			
			Logger.verifyEquals("200", needcollectionmobileCall.getString("code"), "验证code");
			Logger.verifyEquals(true, needcollectionmobileCall.getCollectionMobile(), "验证collectionMobile");
			Logger.verifyEquals(true, needcollectionmobileCall.getNeedInvitationCode(), "验证getNeedInvitationCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}